﻿'*******************************************************************************************
'* Copyright Brügmann Software GmbH, Papenburg
'* Author: Björn Kremer
'* Contact: codeplex<at>patorg.de
'* 
'* VB.CMIS is a VB.NET implementation of the Content Management Interoperability Services (CMIS) standard
'*
'* This file is part of VB.CMIS.
'* 
'* VB.CMIS is free software: you can redistribute it and/or modify
'* it under the terms of the GNU Lesser General Public License as published by
'* the Free Software Foundation, either version 3 of the License, or
'* (at your option) any later version.
'* 
'* VB.CMIS is distributed in the hope that it will be useful,
'* but WITHOUT ANY WARRANTY; without even the implied warranty of
'* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'* GNU Lesser General Public License for more details.
'* 
'* You should have received a copy of the GNU Lesser General Public License
'* along with VB.CMIS. If not, see <http://www.gnu.org/licenses/>.
'*******************************************************************************************
Imports CMISObjectModel

Public Class TypeData
   Public Const RootDocumentType As String = "cmis:document"
   Public Const Document1Type As String = "sampleDocumentType1"
   Public Const RootFolderType As String = "cmis:folder"
   Public Const Folder1Type As String = "sampleFolderType1"
   Public Const RootRelationshipType As String = "cmis:relationship"
   Public Const Relationship1Type As String = "sampleRelationship1"
   Public Const RootPolicyType As String = "cmis:policy"
   Public Const RootSecondaryType As String = "cmis:secondary"
   Public Const RootItem As String = "cmis:item"
   Public Property Definition As TypeDefinitions.TypeDefinition
   Public Property CreationDate As DateTime = Now
   Public Property CreatedBy As String = "test"


 
   Public ReadOnly Property Author As String
      Get
         Return CreatedBy & "@example.org"
      End Get
   End Property
   Public Property Children As Dictionary(Of String, TypeData)
   Public Property IsBaseType As Boolean = False
  

   Public Sub New(type As TypeDefinitions.TypeDefinition, isBaseType As Boolean, children As Dictionary(Of String, TypeData))
      Me.Definition = type
      Me.Children = children
      Me.IsBaseType = isBaseType
    
      AddHandler FindParentEvent, AddressOf FindParentHandler


   End Sub
   Public Overrides Function ToString() As String
      Return Me.Definition.Id & " - " & MyBase.ToString()
   End Function

   Private Shared Event FindParentEvent(sender As Object, e As FindParentEventArgs(Of TypeData))
   Public Shared Function FindParent(pkey As String) As List(Of TypeData)
      Dim tmpArgs As New FindParentEventArgs(Of TypeData)(pkey)
      RaiseEvent FindParentEvent(Nothing, tmpArgs)
      Return tmpArgs.ResultData
   End Function



   Private Sub FindParentHandler(sender As Object, e As FindParentEventArgs(Of TypeData))
      If Children.ContainsKey(e.SearchPkey) Then
         e.ResultData.Add(Me)
      End If
   End Sub
End Class
